import { fromJS } from 'immutable'
import * as constants from './constants'

const defaultState = fromJS({
  topicList: [],
  articleList: [],
  articlePage: 1,
  showTop: false,
})

export default (state = defaultState, action) => {
  switch (action.type) {
    case constants.CHANGE_HOME:
      return state.set('topicList', fromJS(action.topicList))
    case constants.ADD_ARTICLE:
      return state.merge({
        articleList: state.get('articleList').concat(action.list),
        articlePage: action.nextPage
      })
    case constants.TOGGLESHOW:
      return state.set('showTop', action.show)
    default:
      return state
  }
}